import 'package:flutter/material.dart';
import 'package:flutter_soundmagus/widget/zfbutton.dart';
import 'package:flutter_soundmagus/widget/zflistview.dart';
import 'package:get/get_state_manager/get_state_manager.dart';

///通道列表
class ZFChView extends StatelessWidget {
  ///通道是否选中
  final bool Function(int index)? isSelect;

  ///通道点击
  final void Function(int index)? onPressed;

  ///通道长按
  final void Function(int index)? onDoubleTap;
  const ZFChView({Key? key, this.onPressed, this.onDoubleTap, this.isSelect})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: 44,
      child: ZFListView(
          scrollDirection: Axis.horizontal,
          itemBuilder: (context, i) => Obx(() => ZFButton(
                title: 'CH${i + 1}',
                selected: isSelect != null ? isSelect!(i) : false,
                onPressed: () => onPressed?.call(i),
                onDoubleTap: () => onDoubleTap?.call(i),
              )),
          separatorBuilder: (context, i) {
            return VerticalDivider(
              color: Colors.grey,
              indent: 10,
              endIndent: 10,
              width: 2,
            );
          },
          itemCount: 8),
    );
  }
}
